#!/bin/bash
set -e

function info() {
echo Usage: `basename $0` [-i in.bed] in.bam
exit 65
}

while getopts  ":i:b:p:" opts
do
        case  $opts  in
        i) interval=$OPTARG;;
		b) asemmbly=$OPTARG;;
		p) out_prefix=$OPTARG;;
		*) info;;
        esac
done
shift $(($OPTIND - 1))

if [ -z $1 ]; then info; fi


. /mnt/ilustre/app/medical/tools/.var


if test -z "$interval"; then
echo no interval file.
echo gatk UnifiedGenotyper
java -Xmx$java_memory -jar $gatk \
	-T UnifiedGenotyper \
	-R $ref_genome \
	-I $1 \
	-o $out_prefix.snp.vcf \
	-glm SNP \
	-baq CALCULATE_AS_NECESSARY \
	--baqGapOpenPenalty 30.0 \
	--downsample_to_coverage 250 \
	-stand_call_conf 30.0 \
	-stand_emit_conf 20.0 \
	--min_base_quality_score 20 \
	-contamination 0.00001 \
	--max_deletion_fraction 2 \
	-nt 8
	# -nct 2 \
	
else
echo interval: $interval.
echo gatk UnifiedGenotyper
java -Xmx$java_memory -Djava.io.tmpdir=$tmp -jar $gatk \
	-T UnifiedGenotyper \
	-R $ref_genome \
	-I $1 \
	-o $out_prefix.snp.vcf \
	-glm SNP \
	-baq CALCULATE_AS_NECESSARY \
	--baqGapOpenPenalty 30.0 \
	--downsample_to_coverage 250 \
	-stand_call_conf 30.0 \
	-stand_emit_conf 20.0 \
	--min_base_quality_score 20 \
	-contamination 0.00001 \
	--max_deletion_fraction 2 \
	-L $interval \
	-nt 8
	# -nct 2 \

fi

	
# --max_deletion_fraction # If the fraction of reads with deletions spanning a locus is greater than this value, the site will not be considered callable and will be skipped. To disable the use of this parameter, set its value to >1.
# --min_indel_fraction_per_sample #for indel # Minimum fraction of all reads at a locus that must contain an indel (of any allele) for that sample to contribute to the indel count for alleles
# -contamination # Fraction of contamination in sequencing data (for all samples) to aggressively remove
# --downsample_to_coverage 250 #default
	
# echo 2>>$log 1>&2
# echo 2>>$log 1>&2
# echo gatk UnifiedGenotyper 2>>$log 1>&2
# java -Xmx$java_memory -jar $gatk \
	# -T UnifiedGenotyper \
	# -R $ref_genome \
	# -I 1.realn.recal.bam \
	# -o 1.indel.vcf \
	# -glm INDEL \
	# -baq CALCULATE_AS_NECESSARY \
	# --baqGapOpenPenalty 30.0 \
	# --downsample_to_coverage 2000 \
	# -nt 8 \
	# -nct 2 \
	# --min_indel_fraction_per_sample 0.25 \
	# --min_indel_count_for_genotyping 20 \
	# -stand_call_conf 50.0 \
	# -stand_emit_conf 30.0 \
	# --min_base_quality_score 20 \
	# --max_deletion_fraction 0.3 \
	# -L ${intervals}
